﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class TypeProcess_NewForm : System.Web.UI.Page
{
    private int ID
    {
        get
        {
            if (Request.QueryString["id"] == null)
                return 0;
            else
                return int.Parse(Request.QueryString["id"]);
        }
    }

    

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
        Model.TypeProcessManager typeProcessManager = new Model.TypeProcessManager();
       Model.TypeProcess  typeProcess = typeProcessManager.GetById(ID);
        txtName.Text = typeProcess.Name;
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        Model.TypeProcessManager typeProcessManager = new Model.TypeProcessManager();
        Model.TypeProcess typeProcess = typeProcessManager.GetById(ID);
        typeProcess.Name = txtName.Text;

        int newArticleID = typeProcessManager.Update(typeProcess);

        //if the new article was successfuly added to the database...
        if (newArticleID != 0)
        {
            lblConfirmation.Text = "The new article has been successfuly saved!";
            lblConfirmation.Visible = true;
        }
        else
        {
            lblConfirmation.Text = "Oups! Something went wrong!";
            lblConfirmation.Visible = true;
        }
        Response.Redirect("ListView.aspx");
        //ClearForm();
    }

    

    protected void btnGoBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("ListView.aspx");
    }
}